package MyTest;

public class N3 {
    public static void main(String[] args) {
        int N = 6;
        String ss = "010101";

        int[] select_dp = new int[N];
        int[] noselect_dp = new int[N];

        select_dp[0] = 1;
        noselect_dp[0] = 0;
        select_dp[1] = (ss.charAt(1) == ss.charAt(0))? 3 : 2;
        noselect_dp[1] = 1;

        for(int i=2; i<N; i++){
            int select_1 = (ss.charAt(i) == ss.charAt(i-1))? (select_dp[i-1] + ss.charAt(i-1) - '0' + 1) : (select_dp[i-1] + 1);
            int select_2 = (ss.charAt(i) == ss.charAt(i-2))? (select_dp[i-2] + ss.charAt(i-2) - '0' + 1) : (select_dp[i-2] + 1);
            int no_select = Math.max(select_dp[i-1], noselect_dp[i-1]);
            select_dp[i] = Math.max(select_1, select_2);
            noselect_dp[i] = no_select;
            System.out.println(i + ": " + select_dp[i] + " "+ noselect_dp[i]);
        }
        System.out.println(Math.max(select_dp[N-1], noselect_dp[N-1]));
    }
}
